<?php
class Admin_goods extends Controller{
	function Admin_goods(){
		parent::Controller();
	}
	function sortgoods(){
		$data=$this->commonmodel->getsort('gaoji_productsort');
		$getchild=$this->commonmodel->getchildren($data,0,0);
		$data['child']=$getchild;
		$this->load->view('admin_sortgoods',$data);
	}
	function updategoodsindex(){
		$data=$this->commonmodel->getsort('gaoji_productsort');
		$getchild=$this->commonmodel->getchildren($data,0,0);
		$data['child']=$getchild;
		$data['query']=$this->commonmodel->get_where('gaoji_product','newsid',$this->uri->segment(3));
		$this->load->view('admin_updategoods',$data);
	}
	function somesort(){
		//$data['query']=$this->commonmodel->page_where('gaoji_product','sortid',$this->uri->segment(3));
		$page_num = '2';//每页的数据
		//$a=$this->uri->segment(4)?0:$this->uri->segment(4);
		//exit;
		$data= $this->commonmodel->page_where('gaoji_product',$page_num,$this->uri->segment(4),'sortid',$this->uri->segment(3));
		$cat= $this->uri->segment(3);
		$total_nums=$this->commonmodel->nums_where('gaoji_product','sortid',$cat);//这里得到从数据库中的总页数
		//echo $total_nums;
		$data['query']=$data[0];//把查询结果放到$data['query']中
		$this->load->library('pagination');
		$config['base_url'] = $this->config->item('base_url').'/index.php/admin_goods/somesort/'.$this->uri->segment(3).'/';
		$config['total_rows'] = $total_nums;//总共多少条数据
		$config['per_page'] = $page_num;//每页显示几条数据
		$config['full_tag_open'] = '<p>';
		$config['full_tag_close'] = '</p>';
		$config['first_link'] = '首页';
		$config['first_tag_open'] = '<li>';//“第一页”链接的打开标签。
		$config['first_tag_close'] = '</li>';//“第一页”链接的关闭标签。
		$config['last_link'] = '尾页';//你希望在分页的右边显示“最后一页”链接的名字。
		$config['last_tag_open'] = '<li>';//“最后一页”链接的打开标签。
		$config['last_tag_close'] = '</li>';//“最后一页”链接的关闭标签。
		$config['next_link'] = '下一页';//你希望在分页中显示“下一页”链接的名字。
		$config['next_tag_open'] = '<li>';//“下一页”链接的打开标签。
		$config['next_tag_close'] = '</li>';//“下一页”链接的关闭标签。
		$config['prev_link'] = '上一页';//你希望在分页中显示“上一页”链接的名字。
		$config['prev_tag_open'] = '<li>';//“上一页”链接的打开标签。
		$config['prev_tag_close'] = '</li>';//“上一页”链接的关闭标签。
		$config['cur_tag_open'] = '<li class="current">';//“当前页”链接的打开标签。
		$config['cur_tag_close'] = '</li>';//“当前页”链接的关闭标签。
		$config['num_tag_open'] = '<li>';//“数字”链接的打开标签。
		$config['num_tag_close'] = '</li>';
		$config['uri_segment']=4;
	
		$this->pagination->initialize($config);
		//print_r($data);
		//exit;
		$this->load->view('admin_somesortgoods.php',$data);
	}
	/*
	function listgoodsbak()
	{
		$page_num = '10';//每页的数据
		$data= $this->commonmodel->page('gaoji_product',$page_num,$this->uri->segment(3));
		$total_nums=$this->commonmodel->nums('gaoji_product');//这里得到从数据库中的总页数
		$data['query']=$data[0];//把查询结果放到$data['query']中
		$this->load->library('pagination');
		$config['base_url'] = $this->config->item('base_url').'/index.php/admin_goods/listgoods/';
		$config['total_rows'] = $total_nums;//总共多少条数据
		$config['per_page'] = $page_num;//每页显示几条数据
		$config['full_tag_open'] = '<p>';
		$config['full_tag_close'] = '</p>';
		$config['first_link'] = '首页';
		$config['first_tag_open'] = '<li>';//“第一页”链接的打开标签。
		$config['first_tag_close'] = '</li>';//“第一页”链接的关闭标签。
		$config['last_link'] = '尾页';//你希望在分页的右边显示“最后一页”链接的名字。
		$config['last_tag_open'] = '<li>';//“最后一页”链接的打开标签。
		$config['last_tag_close'] = '</li>';//“最后一页”链接的关闭标签。
		$config['next_link'] = '下一页';//你希望在分页中显示“下一页”链接的名字。
		$config['next_tag_open'] = '<li>';//“下一页”链接的打开标签。
		$config['next_tag_close'] = '</li>';//“下一页”链接的关闭标签。
		$config['prev_link'] = '上一页';//你希望在分页中显示“上一页”链接的名字。
		$config['prev_tag_open'] = '<li>';//“上一页”链接的打开标签。
		$config['prev_tag_close'] = '</li>';//“上一页”链接的关闭标签。
		$config['cur_tag_open'] = '<li class="current">';//“当前页”链接的打开标签。
		$config['cur_tag_close'] = '</li>';//“当前页”链接的关闭标签。
		$config['num_tag_open'] = '<li>';//“数字”链接的打开标签。
		$config['num_tag_close'] = '</li>';
		$this->pagination->initialize($config);
		$this->load->view('admin_listgoods',$data);
	}
	*/
	function addsortindex(){
		$data=$this->commonmodel->getsort('gaoji_productsort');
		$getChild=$this->commonmodel->getchildren($data,0,0);
		$data['child']=$getChild;
		$this->load->view('admin_addsort',$data);
	}
	function addsort(){
		$data=array(
		'title'=>$_POST['title'],
		'pid'=>$_POST['sortid'],
		);
		$this->commonmodel->insert('gaoji_productsort',$data);
	}
	function addgoodsindex(){
		$data=$this->commonmodel->getsort('gaoji_productsort');
		$getChild=$this->commonmodel->getchildren($data,0,0);
		$data['child']=$getChild;
		$this->load->view('admin_addgoods',$data);
	}
	function addgoods(){
		$this->load->library('upload');
		$userfile_data = $_FILES['userfile'];
		$imgname_one = $this->upload->do_upload_ex("userfile",$userfile_data,false,"/uploads/goods/","/uploads/goods_thumb/",true); //单图片上传 缩略图生
		$_POST['picture']=$imgname_one[0];
		$this->commonmodel->insert('gaoji_product',$_POST);
		echo "<meta http-equiv='Content-Type'' content='text/html; charset=utf-8'>";
		echo "<script language='JavaScript'>alert('添加成功');</script>";
		redirect('/admin_goods/addgoodsindex','refresh');
	}
	
	function listgoods(){
		$page_num = '2';//每页的数据
		$ab=$this->uri->segment(3)?$this->uri->segment(3):1;
		$total_nums=$this->commonmodel->nums('gaoji_product');//这里得到从数据库中的总页数
		$data['query']=$this->commonmodel->sql_self("SELECT gaoji_product.* ,gaoji_productsort.title as b FROM gaoji_product,gaoji_productsort WHERE gaoji_product.sortid=gaoji_productsort.sortid  order by b desc limit $ab,$page_num");
		$this->load->library('pagination');
		$config['base_url'] = $this->config->item('base_url').'/index.php/admin_goods/listgoods/';
		$config['total_rows'] = $total_nums;//总共多少条数据
		$config['per_page'] = $page_num;//每页显示几条数据
		$config['full_tag_open'] = '<p>';
		$config['full_tag_close'] = '</p>';
		$config['first_link'] = '首页';
		$config['first_tag_open'] = '<li>';//“第一页”链接的打开标签。
		$config['first_tag_close'] = '</li>';//“第一页”链接的关闭标签。
		$config['last_link'] = '尾页';//你希望在分页的右边显示“最后一页”链接的名字。
		$config['last_tag_open'] = '<li>';//“最后一页”链接的打开标签。
		$config['last_tag_close'] = '</li>';//“最后一页”链接的关闭标签。
		$config['next_link'] = '下一页';//你希望在分页中显示“下一页”链接的名字。
		$config['next_tag_open'] = '<li>';//“下一页”链接的打开标签。
		$config['next_tag_close'] = '</li>';//“下一页”链接的关闭标签。
		$config['prev_link'] = '上一页';//你希望在分页中显示“上一页”链接的名字。
		$config['prev_tag_open'] = '<li>';//“上一页”链接的打开标签。
		$config['prev_tag_close'] = '</li>';//“上一页”链接的关闭标签。
		$config['cur_tag_open'] = '<li class="current">';//“当前页”链接的打开标签。
		$config['cur_tag_close'] = '</li>';//“当前页”链接的关闭标签。
		$config['num_tag_open'] = '<li>';//“数字”链接的打开标签。
		$config['num_tag_close'] = '</li>';
		$this->pagination->initialize($config);
		$this->load->view('admin_listgoods',$data);
	}
	function updateindex(){
		$data=$this->commonmodel->getsort('gaoji_productsort');
		$getchild=$this->commonmodel->getchildren($data,0,0);
		$data['child']=$getchild;
	$data['query']=$this->commonmodel->get_where('gaoji_product','productid',$this->uri->segment(3));
		$this->load->view('admin_updategoods',$data);
	}
	function updategoods(){
		
	}
}